package cz.kz.cmdapp;

import cz.kz.model.KZUser;
import cz.kz.model.KZEntry;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.List;
import java.util.Collection;

/**
 * Database connection: ij
 * > connect 'jdbc:derby:database';
 *
 *
 * User: lzap
 * Date: 31.10.2007
 * Time: 23:12:10
 */
public class TestingQueries {
    public static void main(String[] args) {

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("kzPersistenceUnit");
        EntityManager em = emf.createEntityManager();

        KZUser wlk = (KZUser) em.createQuery("SELECT u FROM KZUser u WHERE u.login LIKE :login").setParameter("login", "wlk").getResultList().get(0);
        System.out.println("Wlk ma heslo: " + wlk.getPassword());

        List allUsers = em.createNamedQuery("User.findAll").getResultList();
        for (Object o: allUsers) {
            KZUser u = (KZUser) o;
            Collection<KZEntry> entries = u.getEntries();
            for (KZEntry e: entries) {
                System.out.println(e);
            }
        }


    }
}
